package lemon.kenhnhacvn;

import java.io.Serializable;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import saucaca.CustomView.CustomActionbar;
import saucaca.Database.DataBase;
import saucaca.JSON.JsonReader;
import saucaca.JSON.WServiceLib;
import saucaca.Object.SongObject;
import saucaca.Slidingmenu.SlidingMenu;
import saucaca.Slidinguppanel.SlidingUpPanelLayout;
import saucaca.Util.FileUtils;
import saucaca.Util.TagName;
import saucaca.fragment.FragmentErrorConnect;
import saucaca.fragment.LocalAllMusic;
import saucaca.fragment.MenuFragment;
import android.annotation.SuppressLint;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.text.format.Formatter;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

public class BaseActivity extends FragmentActivity {
	private static final String TAG = BaseActivity.class.getSimpleName();
	public SlidingMenu mSlidingMenu = null;
	public SlidingUpPanelLayout mSilidingUP;
	public List<Fragment> mFragmentList = new ArrayList<Fragment>();
	public MenuFragment menuFragment;
	public Fragment mCurrentFragment = null;
	public static final String ID = "id";
	public static final String INDEX = "index";

	ImageView imgMenuNavigate, imgMini_album;
	TextView textTitle, textArtist, textBufferStart, textBufferEnd;
	SeekBar SeekbarBuffer;
	public static final String SONGS_MUSIC = "allmusic";
	public static final String ARTIST_MUSIC = "singermusic";
	public static final String ALBUM_MUSIC = "albummusic";
	public static final String FILE_MUSIC = "filemusic";
	public static final String PLAYLIST_MUSIC = "playlistmusic";
	public static final String VIDEO_MUSIC = "videomusic";
	public static final String Key_Title = "txt1";
	public static final String Key_Artist = "txt2";
	public static final String Key_Music = "music";
	public static final String Key_Image = "IMG";
	public static final String Key_List = "list";
	static DataBase db;
	public static ArrayList<SongObject> mMusicList = new ArrayList<SongObject>();
	public static ArrayList<Map<String, Object>> allMusicMap = new ArrayList<Map<String, Object>>();
	public static ArrayList<Map<String, Object>> allVideoMap = new ArrayList<Map<String, Object>>();
	public static ArrayList<Map<String, Object>> singerMusicMap = new ArrayList<Map<String, Object>>();
	public static ArrayList<Map<String, Object>> albumMusicMap = new ArrayList<Map<String, Object>>();
	public static ArrayList<Map<String, Object>> fileMusicMap = new ArrayList<Map<String, Object>>();
	public static ArrayList<Map<String, Object>> playListMusicMap = new ArrayList<Map<String, Object>>();
	public static ImageLoader imageLoader = ImageLoader.getInstance();
	public static DisplayImageOptions options;
	View controllayout, controllayout2;
	// public static Animation AlbumAnimation;
	public static int w = 0, h = 0;
	public static android.widget.LinearLayout.LayoutParams linear_params_3;
	public static android.widget.LinearLayout.LayoutParams linear_params_2;
	static Context context;

	public static ArrayList<SongObject> currentPlaylist = new ArrayList<SongObject>();
	public static int currentIndex;
	public static long currentDuration;
	public CustomActionbar myActionBar;

	public static String IP = "";
	public static String IS3G = "";
	public static boolean NETWORK_CONNECTED = false;

	private static String NET_3G = "1";
	private static String NET_WIFI = "0";
	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.layout_content);
		IP = getLocalIpAddress();
		if (BaseEngine.isWifiConnected(BaseActivity.this)) {
			IS3G = NET_WIFI;
			NETWORK_CONNECTED = true;
		}
		if (BaseEngine.isMobileConnected(BaseActivity.this)) {
			IS3G = NET_3G;
			NETWORK_CONNECTED = true;
		}
		myActionBar = (CustomActionbar) findViewById(R.id.main_actionbar);
		DisplayMetrics metrics = getResources().getDisplayMetrics();
		w = (int) metrics.widthPixels;
		h = (int) metrics.heightPixels;
		initSlidingMenu();
		if (savedInstanceState == null) {
			initPopulateFragment();
		}

		findviewbyid();
		db = new DataBase(this);
		context = getApplicationContext();
		options = new DisplayImageOptions.Builder().showImageOnFail(R.drawable.ic_default).showStubImage(R.drawable.ic_default).showImageForEmptyUri(R.drawable.ic_default)
				.cacheInMemory().cacheOnDisc().build();
		initMediaData();

		int w = (int) (BaseActivity.w * 0.9 / 3);
		int h = w / 2;
		linear_params_3 = new android.widget.LinearLayout.LayoutParams(w, h);

		linear_params_2 = new android.widget.LinearLayout.LayoutParams((int) (BaseActivity.w * 0.9 / 2), (int) (BaseActivity.w * 0.9 / 2) / 2);
	}

//	@Override
//	protected void onSaveInstanceState(Bundle outState) {
//		super.onSaveInstanceState(outState);
//	}

	public void showPanelControl(boolean isShow) {
		if (mSilidingUP != null) {
			if (!isShow) {
				// if (!mSilidingUP.isPanelHidden()) {
				mSilidingUP.hidePanel();
			} else {
				mSilidingUP.showPanel();
			}
		}
	}

	private void findviewbyid() {

		controllayout = findViewById(R.id.panel);
		controllayout2 = findViewById(R.id.panel_details);

		imgMini_album = (ImageView) findViewById(R.id.mini_picture_control);
	}

	public void setSlideEnable(boolean slidable) {
		if (slidable) {
			mSlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
		} else {
			mSlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
		}
	}

	private void initSlidingMenu() {
		mSlidingMenu = new SlidingMenu(this);
		mSlidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
		mSlidingMenu.setMenu(R.layout.menu);
		mSlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
		mSlidingMenu.setMode(SlidingMenu.LEFT);
		mSlidingMenu.setShadowWidthRes(R.dimen.shadow_width);
		mSlidingMenu.setShadowDrawable(R.drawable.shadow);
		mSlidingMenu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
		mSlidingMenu.setFadeDegree(0.5f);
		mSlidingMenu.setBehindScrollScale(0.4f);
	}

	private void initPopulateFragment() {
		menuFragment = MenuFragment.getInstance(this);
		// menuFragment = new MenuFragment(BaseActivity.this);
		if (NETWORK_CONNECTED) {
			mCurrentFragment = new LocalAllMusic();// new home();
		} else
			mCurrentFragment = new LocalAllMusic();
		FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
		fragmentTransaction.replace(R.id.frame_menu, menuFragment, menuFragment.getClass().getName());
		fragmentTransaction.replace(R.id.frame_main, mCurrentFragment, mCurrentFragment.getClass().getName());
		fragmentTransaction.commit();
		mFragmentList.add(mCurrentFragment);
	}

	public void switchContent(String fragmentName) {
		Fragment f = null;
		boolean existed = false;
		if(mCurrentFragment!=null){
			if (!mCurrentFragment.getClass().getName().equals(fragmentName)) {
				for (int i = 0; i < mFragmentList.size(); i++) {
					if (mFragmentList.get(i).getClass().getName().equals(fragmentName)) {
						existed = true;
						f = mFragmentList.get(i);
						FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
						fragmentTransaction.hide(mCurrentFragment).show(f);
						fragmentTransaction.commit();
						mCurrentFragment = f;
						break;
					}
				}
				if (!existed) {
					f = Fragment.instantiate(getApplicationContext(), fragmentName);
					mFragmentList.add(f);
					FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
					fragmentTransaction.hide(mCurrentFragment).add(R.id.frame_main, f);
					fragmentTransaction.commit();
					mCurrentFragment = f;
				}
			}
		}else{
			f = Fragment.instantiate(getApplicationContext(), fragmentName);
			mFragmentList.add(f);
			FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
			fragmentTransaction.add(R.id.frame_main, f);
			fragmentTransaction.commit();
		}
		mSlidingMenu.showContent();
	}

	public void showprevousFragment() {
		Fragment f = null;
		try {
			if (mFragmentList.size() > 0)
				for (int i = 0; i < mFragmentList.size(); i++) {
					if (mFragmentList.get(i).getClass().getName().equals(mCurrentFragment.getClass().getName())) {
						if (mFragmentList.get(i - 1).getClass().getName() != FragmentErrorConnect.class.getName()) {
							f = mFragmentList.get(i - 1);
							getSupportFragmentManager().beginTransaction().hide(mCurrentFragment).show(f).commit();
							getSupportFragmentManager().beginTransaction().remove(mFragmentList.get(i)).commit();
							mFragmentList.remove(i);
						} else {
							f = mFragmentList.get(i - 2);
							getSupportFragmentManager().beginTransaction().hide(mCurrentFragment).show(f).commit();
							getSupportFragmentManager().beginTransaction().remove(mFragmentList.get(i)).commit();
							mFragmentList.remove(i);
							mFragmentList.remove(i - 1);
						}
						mCurrentFragment = f;
						break;
					}
				}
		} catch (Exception e) {
			// TODO: handle exception
		}
		mSlidingMenu.showContent();
	}

	@SuppressLint("Recycle")
	public void reloadFragment(Serializable data) {
		if (mFragmentList.size() > 0) {
			getSupportFragmentManager().beginTransaction().detach(mCurrentFragment).commit();
			Bundle arguments = mCurrentFragment.getArguments();
			arguments.putSerializable(ID, data);
			getSupportFragmentManager().beginTransaction().attach(mCurrentFragment).commit();
		}
		mSlidingMenu.showContent();
	}

	public void switchContent(String fragmentName, String data) {
		Fragment f = null;
		boolean existed = false;
		if(mCurrentFragment!=null){
			if (!mCurrentFragment.getClass().getName().equals(fragmentName)) {
				for (int i = 0; i < mFragmentList.size(); i++) {
					if (mFragmentList.get(i).getClass().getName().equals(fragmentName)) {
						existed = true;
						f = mFragmentList.get(i);
						Bundle arguments = f.getArguments();
						arguments.putString(ID, data);
						FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
						fragmentTransaction.hide(mCurrentFragment).show(f);
						fragmentTransaction.commit();
						mCurrentFragment = f;
						break;
					}
				}
				if (!existed) {
					f = Fragment.instantiate(getApplicationContext(), fragmentName);
					Bundle arguments = new Bundle();
					arguments.putString(ID, data);
					f.setArguments(arguments);
					mFragmentList.add(f);
					FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
					fragmentTransaction.hide(mCurrentFragment).add(R.id.frame_main, f);
					fragmentTransaction.commit();
					mCurrentFragment = f;
				}
			}
		}else{
			f = Fragment.instantiate(getApplicationContext(), fragmentName);
			Bundle arguments = new Bundle();
			arguments.putString(ID, data);
			f.setArguments(arguments);
			mFragmentList.add(f);
			FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
			fragmentTransaction.add(R.id.frame_main, f);
			fragmentTransaction.commit();
		}
		mSlidingMenu.showContent();
	}

	public void menuselect(String fragmentName) {
		Fragment f = null;
		try {
			if(mCurrentFragment!=null){
			f = Fragment.instantiate(getApplicationContext(), fragmentName);
			mFragmentList.add(f);
			FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
			fragmentTransaction.hide(mCurrentFragment).add(R.id.frame_main, f);
			fragmentTransaction.commit();
			mCurrentFragment = f;
			if (mFragmentList.size() > 1)
				for (int i = 0; i < mFragmentList.size() - 1; i++) {
					getSupportFragmentManager().beginTransaction().remove(mFragmentList.get(i)).commit();
					mFragmentList.remove(i);
				}
			}else{
				f = Fragment.instantiate(getApplicationContext(), fragmentName);
				mFragmentList.add(f);
				FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
				fragmentTransaction.add(R.id.frame_main, f);
				fragmentTransaction.commit();
			}
		} catch (Exception e) {
		}
		mSlidingMenu.showContent();
	}

	public void switchContent(Fragment fragment) {
		if(mCurrentFragment!=null){
		if (!mCurrentFragment.getClass().getName().equals(fragment.getClass().getName())) {
			mFragmentList.add(fragment);
			FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
			fragmentTransaction.hide(mCurrentFragment).add(R.id.frame_main, fragment);
			fragmentTransaction.commit();
			mCurrentFragment = fragment;
		}
	}else{
		mFragmentList.add(fragment);
		FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
		fragmentTransaction.add(R.id.frame_main, fragment);
		fragmentTransaction.commit();
	}
		mSlidingMenu.showContent();
	}

	public void switchContent(String fragmentName, Serializable data) {
		Fragment f = null;
		boolean existed = false;
		if(mCurrentFragment!=null){
		if (!mCurrentFragment.getClass().getName().equals(fragmentName)) {

			for (int i = 0; i < mFragmentList.size(); i++) {
				if (mFragmentList.get(i).getClass().getName().equals(fragmentName)) {
					existed = true;
					f = mFragmentList.get(i);
					Bundle arguments = f.getArguments();
					arguments.putSerializable(ID, data);
					FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
					fragmentTransaction.hide(mCurrentFragment).show(f);
					fragmentTransaction.commit();
					mCurrentFragment = f;
					break;
				}
			}
			if (!existed) {
				f = Fragment.instantiate(getApplicationContext(), fragmentName);
				Bundle arguments = new Bundle();
				arguments.putSerializable(ID, data);
				f.setArguments(arguments);
				mFragmentList.add(f);
				FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
				fragmentTransaction.hide(mCurrentFragment).add(R.id.frame_main, f);
				fragmentTransaction.commit();
				mCurrentFragment = f;
			}
		}}else{
			f = Fragment.instantiate(getApplicationContext(), fragmentName);
			Bundle arguments = new Bundle();
			arguments.putSerializable(ID, data);
			f.setArguments(arguments);
			mFragmentList.add(f);
			FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
			fragmentTransaction.add(R.id.frame_main, f);
			fragmentTransaction.commit();
		}
		mSlidingMenu.showContent();
	}

	public void switchContent(String fragmentName, String data, int indext) {
		Fragment f = null;
		boolean existed = false;
		if(mCurrentFragment!=null){
		if (!mCurrentFragment.getClass().getName().equals(fragmentName)) {

			for (int i = 0; i < mFragmentList.size(); i++) {
				if (mFragmentList.get(i).getClass().getName().equals(fragmentName)) {
					existed = true;
					f = mFragmentList.get(i);
					Bundle arguments = f.getArguments();
					arguments.putString(ID, data);
					arguments.putInt(INDEX, indext);
					FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
					fragmentTransaction.hide(mCurrentFragment).show(f);
					fragmentTransaction.commit();
					mCurrentFragment = f;
					break;
				}
			}
			if (!existed) {
				f = Fragment.instantiate(getApplicationContext(), fragmentName);
				Bundle arguments = new Bundle();
				arguments.putString(ID, data);
				arguments.putInt(INDEX, indext);
				f.setArguments(arguments);
				mFragmentList.add(f);
				FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
				fragmentTransaction.hide(mCurrentFragment).add(R.id.frame_main, f);
				fragmentTransaction.commit();
				mCurrentFragment = f;
			}
			TagName.showLogError(TAG, "SwitchContent data: exited:" + existed);
		}}else{
			f = Fragment.instantiate(getApplicationContext(), fragmentName);
			Bundle arguments = new Bundle();
			arguments.putString(ID, data);
			arguments.putInt(INDEX, indext);
			f.setArguments(arguments);
			mFragmentList.add(f);
			FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
			fragmentTransaction.add(R.id.frame_main, f);
			fragmentTransaction.commit();
		}
		mSlidingMenu.showContent();
	}

	public SlidingMenu getSlidingMenu() {
		return mSlidingMenu;
	}

	public void clear() {
		if (mFragmentList.size() > 0) {
			for (int i = 0; i < mFragmentList.size(); i++) {
				getSupportFragmentManager().beginTransaction().remove(mFragmentList.get(i)).commit();
			}
			mFragmentList.clear();
		}
	}

	@Override
	protected void onDestroy() {
		mFragmentList.clear();
		mFragmentList = null;
		super.onDestroy();
	}

	public static void initMediaData() {
		mMusicList.clear();
		allMusicMap.clear();
		singerMusicMap.clear();
		albumMusicMap.clear();
		fileMusicMap.clear();
		allVideoMap.clear();

		ContentResolver contentResolver = context.getContentResolver();

		// query all music
		Cursor cursor = contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
		if (cursor == null)
			return;
		while (cursor.moveToNext()) {
			SongObject music = new SongObject();
			music.setSONG_ID(Integer.toString(cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID))));
			music.setTXNAME(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE)));
			music.setNAME_SINGERS(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST)));
			music.setALBUM(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM)));
			music.setPATCH_FULL(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA)));
			music.setSize(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE));
			music.setduration(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION));
			music.setFormNet(false);
			mMusicList.add(music);

			Map<String, Object> map = new HashMap<String, Object>();
			map.put(Key_Title, music.getTXNAME());
			map.put(Key_Artist, music.getNAME_SINGERS());
			map.put(Key_Music, music);
			allMusicMap.add(map);
		}
		cursor.close();

		// query artist
		cursor = contentResolver.query(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Artists.DEFAULT_SORT_ORDER);
		while (cursor.moveToNext()) {
			Map<String, Object> map = new HashMap<String, Object>();
			String singer = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST));
			String songcount = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.NUMBER_OF_TRACKS));
			ArrayList<SongObject> musiclist = new ArrayList<SongObject>();
			for (int i = 0; i < mMusicList.size(); i++) {
				if (mMusicList.get(i).getNAME_SINGERS().equals(singer)) {
					musiclist.add(mMusicList.get(i));
				}
			}
			map.put(Key_Title, singer);
			map.put(Key_Artist, songcount + " " + context.getResources().getString(R.string.number_song));
			map.put(Key_List, musiclist);
			singerMusicMap.add(map);
		}
		cursor.close();

		// query album
		cursor = contentResolver.query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
		while (cursor.moveToNext()) {
			Map<String, Object> map = new HashMap<String, Object>();
			String albumname = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM));
			String albumart = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM_ART));
			String singer = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ARTIST));

			ArrayList<SongObject> musiclist = new ArrayList<SongObject>();
			for (int i = 0; i < mMusicList.size(); i++) {
				if (mMusicList.get(i).getALBUM().equals(albumname)) {
					musiclist.add(mMusicList.get(i));
					mMusicList.get(i).setAVATAR(albumart);// add pic in song
				}
			}
			map.put(Key_Title, albumname);
			map.put(Key_Artist, singer);
			map.put(Key_Image, albumart);
			map.put(Key_List, musiclist);
			albumMusicMap.add(map);
		}
		cursor.close();

		// query video
		cursor = contentResolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Video.Media.DEFAULT_SORT_ORDER);
		while (cursor.moveToNext()) {
			SongObject music = new SongObject();
			music.setSONG_ID(Integer.toString(cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID))));
			music.setTXNAME(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME)));
			music.setPATCH_FULL(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA)));
			music.setNAME_SINGERS(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE)));
			music.setFormNet(false);

			Map<String, Object> map = new HashMap<String, Object>();
			map.put(Key_Title, music.getTXNAME());
			map.put(Key_Artist, music.getNAME_SINGERS());
			map.put(Key_Music, music);
			allVideoMap.add(map);
		}
		cursor.close();

		// file
		ArrayList<String> fileList = new ArrayList<String>();
		// list to store file url which contains music
		for (SongObject music : mMusicList) {
			String fileurl = FileUtils.getFileUrlString(music.getPATCH_FULL());
			if (!fileList.contains(fileurl))
				fileList.add(fileurl);
		}
		for (String url : fileList) {
			ArrayList<SongObject> fileMusic = new ArrayList<SongObject>();
			for (SongObject music : mMusicList) {
				if (url.equals(FileUtils.getFileUrlString(music.getPATCH_FULL())))
					fileMusic.add(music);
			}
			Map<String, Object> map = new HashMap<String, Object>();
			map.put(Key_Title, FileUtils.getFileNameString(url));
			map.put(Key_Artist, url);
			map.put(Key_List, fileMusic);
			fileMusicMap.add(map);
		}

		// myplaylist
		refreshPlayList();
	}

	public static void refreshPlayList() {
		playListMusicMap.clear();
		ArrayList<String> playlistList = db.getMyPlayList();
		if (playlistList != null) {
			for (String playlist : playlistList) {
				ArrayList<SongObject> musicInPlayList = db.getMusicInPlayList(playlist);
				Map<String, Object> map = new HashMap<String, Object>();
				map.put(Key_Title, playlist + "");
				map.put(Key_Artist, musicInPlayList.size() + " " + context.getResources().getString(R.string.number_song));
				map.put(Key_List, musicInPlayList);
				playListMusicMap.add(map);
			}
		}
	}

	public static ArrayList<Map<String, Object>> getListShow(String stringShow) {
		if (stringShow.equals(ARTIST_MUSIC)) {
			return singerMusicMap;
		} else if (stringShow.equals(ALBUM_MUSIC)) {
			return albumMusicMap;
		} else if (stringShow.equals(FILE_MUSIC)) {
			return fileMusicMap;
		} else if (stringShow.equals(PLAYLIST_MUSIC)) {
			return playListMusicMap;
		} else if (stringShow.equals(VIDEO_MUSIC)) {
			return allVideoMap;
		} else
			return allMusicMap;
	}

	@Override
	protected void onRestart() {
		super.onRestart();
		Log.i(TAG, "***** onRestart");
	}
	@Override
	protected void onResume() {
		super.onResume();
		Log.i(TAG, "***** onResume");
		IP = getLocalIpAddress();
		initPopulateFragment();
	}
	public static String getLocalIpAddress() {
		try {
			for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
				NetworkInterface intf = en.nextElement();
				for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
					InetAddress inetAddress = enumIpAddr.nextElement();
					if (!inetAddress.isLoopbackAddress()) {
						@SuppressWarnings("deprecation")
						String ip = Formatter.formatIpAddress(inetAddress.hashCode());
						return ip;
					}
				}
			}
		} catch (SocketException ex) {
			Log.e(TAG, ex.toString());
		}
		return null;
	}
}
